package com.netcracker.studportal.server.model;
import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.json.simple.JSONObject;

@Entity
@Table(name = "Faculties")
public class Faculty implements Serializable {
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "my_seq_gen")
    @SequenceGenerator(name = "my_seq_gen", sequenceName = "seq_fac")
	@Column(name= "faculty_id")	
	private Long faculty_id;
		
	@Column(name= "faculty_name")
	private String faculty_name;
	
	@ManyToOne
	@JoinColumn(name = "univ_id")
	private University univer;
		
	//getters
	
	public Long getId(){return this.faculty_id;}
	
	public String getName(){return this.faculty_name;}
	
	public University getUniversity(){return this.univer;}
	
	//setters
	
	public void setId(Long id) {this.faculty_id = id;}
	
	public void setName(String name) {this.faculty_name = name;}
	
	public void setUniversity(University univer) {this.univer = univer;}
	
	public JSONObject kJSON(){
		JSONObject obj=new JSONObject();
		if(this.faculty_id!=null) obj.put("faculty_id", this.faculty_id.toString());
		obj.put("faculty_name", this.faculty_name);
		if(this.univer!=null){
		if(this.univer.getId()!=null) obj.put("univ_id", this.univer.getId().toString());	
		obj.put("univ_name", this.univer.getName());
		obj.put("city", this.univer.getCity());
		}
		return obj;		
	}
}
